﻿/* 设置当前页面标志 */
mlm.currPageSymbol = "multilanguage_res";

/* 页面变量 */
window.pageVariable = {

    /* 语言资源的导入窗体 */
    lanResImportFrm: null,

    /* 语言资源文件处理控件 */
    lanResFileCtrl: null
};

/* 初始化界面 */
function initPage() {
    pageframe.layout.resizeEventList.push(setLayout);

    var handlerObj = new webhandler.webTransferObj("GetLanResStat");
    var context = new webhandler.bizExeContext(bindmlmList);
    webhandler.ajaxHandler.bizRequest(handlerObj, context);
}

/* 设置页面布局 */
function setLayout() {
    var mainFormHeight = pageframe.layout.getTableHeightInForm();
    mlmList.resize(mainFormHeight);
}

/* 绑定多语言数据源 */
function bindmlmList(source) {

    var columns = [];
    $.each(source.TableColumns, function (i, column) {

        if (column == "LanResTable") {
            columns.push({ display: mlm.C0022, name: column, width: 200, align: 'center', adjust: true, createCell: createLanTableCell });
        }
        else {
            columns.push({ display: column, name: column, width: 200, align: 'center' });
        }
    });
    columns.push({ display: mlm.C0019, name: "", width: 150, align: 'center', adjust: true, createCell: createMlmOperaCell });

    var mainFormHeight = pageframe.layout.getTableHeightInForm();
    mlmList = new uicontrol.tableList("mlmStarList",
                                     { isPaging: false,
                                         keyColumn: "LanResTable",
                                         height: mainFormHeight,
                                         columns: columns
                                     });
    mlmList.bindDataSource(source);
}

/* 创建多语言列表的数据表列 */
function createLanTableCell(key, value) { 
    return mlm[value];
}

/* 创建多语言列表的操作列 */
function createMlmOperaCell(key) {
    return "<a href='javascript:void(\"0\")' class='bt-link' tag='" + key + "' onclick='exportLanRes.call(this);'>" + mlm.C0020 + "</a><a href='javascript:void(\"0\")' class='bt-link' tag='" + key + "' onclick='openImportLanRes.call(this);'>" + mlm.C0021 + "</a>";
}

/* 导出语言资源 */
function exportLanRes() {
    var handlerObj = new webhandler.webTransferObj("ExportLanRes", { "TableName": $(this).attr("tag") });
    var context = new webhandler.bizExeContext(function (obj) {
        window.open(obj);
    });
    webhandler.ajaxHandler.bizRequest(handlerObj, context);
}

/* 打开导入语言资源的窗体 */
function openImportLanRes() {
    if (!pageVariable.lanResImportFrm) {
        var m_tableName = $(this).attr("tag");
        pageVariable.lanResImportFrm = new uicontrol.dialog("importLanResFrm", mlm.C0025, { width: 700, height: 150 }, function () { importLanRes(m_tableName); });
    }

    pageVariable.lanResImportFrm.show();
}

/* 导入语言资源 */
function importLanRes(tableName) {
    var handlerObj = new webhandler.webTransferObj("ImportLanRes", { "TableName": tableName });

    if (!pageVariable.lanResFileCtrl) {
        pageVariable.lanResFileCtrl = new uicontrol.file("lanResFile");
    }
    var context = new webhandler.bizExeContext(function (obj) {
        alert(obj);
    });

    pageVariable.lanResFileCtrl.uploadFile(handlerObj, context);
}

/* 填充语言资源 */
function fillPageLanRes() {
    /* 多语言维护 */
    $("#lbLanguageTag").text(mlm.C0015);
    /* 多语言统计数据 */
    $("#lbMlmStar").text(mlm.C0016);
    /* 语言资源文件 */
    $("#lbLanResFile").text(mlm.C0026);
    //"ECMS-多语言维护
    document.title = mlm.C0027;
}